using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using XFFSM;
using XFGameFramework;

public class Fight_Enemy : FSMState
{
    private XFGameFramework.Module module ;
    public PlayerModel player;
    public EnemyModel enemy;
    private FightUIController fightUIController => module.LoadController<FightUIController>();

    private PlayerController playerController => module.LoadController<PlayerController>();
    private GameController gameController => module.LoadController<GameController>();
    private SkillController skillController => module.LoadController<SkillController>(); 

    private EnemyController enemycontroller => module.LoadController<EnemyController>();


    public override void OnEnter()
    {
        

        base.OnEnter();
        
        module = userData as XFGameFramework.Module;
        if (module == null) throw new System.Exception("userData is not Module");

        //获取玩家和敌人数据
        //TODO
        enemy = module.GetModel<EnemyModel>();
        player = playerController.GetPlayerModel();

        enemycontroller.EnemySkillsCDUp();
        EnemyAI();

        Debug.Log("Enter Fight_Enemy");
    }

    /// <summary>
    /// 敌人行为逻辑
    /// </summary>
    void EnemyAI()
    {
        //敌人释放技能
        if (enemycontroller.CanUseSkill(10002))
        {
            怒叨 怒叨 = new 怒叨(enemy, player, 10002);
            怒叨.ApplyAction();
        }
        gameController.SetGameState(GameState.Fight_Player);
        LogUtil.Log("敌人技能CD ： {0}", enemy.skillsCD[1]);
    }
    
    public override void OnExit()
    {
        base.OnExit();
        FightInfo.Instance.Rounds++;//回合数增加
        fightUIController.UpdateAllText(player, enemy);        
        //fightUIController.UpdateHp(player.currentHp, enemy.currentHp);
        
        Debug.Log("Exit Fight_Enemy");
    }
}
